package org.icnmasjid.member.model;
// Generated Feb 5, 2008 8:40:40 AM by Hibernate Tools 3.1.0.beta4

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import org.acegisecurity.GrantedAuthority;
import org.acegisecurity.userdetails.UserDetails;


/**
 * @struts.form include-all="true" extends="BaseForm"
 * @hibernate.class
 *         table="login"
 *
 */

public class Login extends org.icnmasjid.member.model.BaseObject implements java.io.Serializable, UserDetails {


    // Fields

    private Integer id;
    private String username;
    private String password;
    private Timestamp lastLogin;
    private Timestamp lastPasswordChanged;
    private Person person;


    // Constructors
    private GrantedAuthority[] grantedAuthorities;

    /** default constructor */
    public Login() {
    }

	/** minimal constructor */
    public Login(String username, String password) {
        this.username = username;
        this.password = password;
    }

    /** full constructor */
    public Login(String username, String password, Timestamp lastLogin, Timestamp lastPasswordChanged) {
        this.username = username;
        this.password = password;
        this.lastLogin = lastLogin;
        this.lastPasswordChanged = lastPasswordChanged;
    }



    // Property accessors
    /**
     *      *            @hibernate.id
     *             generator-class="native"
     *             type="java.lang.Integer"
     *             column="id"
     *
     */

    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }
    /**
     *      *            @hibernate.property
     *             column="username"
     *             unique="true"
     *             length="50"
     *             not-null="true"
     *
     */

    public String getUsername() {
        return this.username;
    }

    public void setUsername(String username) {
        this.username = username;
    }
    /**
     *      *            @hibernate.property
     *             column="pass_word"
     *             length="50"
     *             not-null="true"
     *
     */

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String passWord) {
        this.password = passWord;
    }
    /**
     *      *            @hibernate.property
     *             column="last_login"
     *             length="19"
     *
     */

    public Timestamp getLastLogin() {
        return this.lastLogin;
    }

    public void setLastLogin(Timestamp lastLogin) {
        this.lastLogin = lastLogin;
    }
    /**
     *      *            @hibernate.property
     *             column="last_password_changed"
     *             length="19"
     *
     */

    public Timestamp getLastPasswordChanged() {
        return this.lastPasswordChanged;
    }

    public void setLastPasswordChanged(Timestamp lastPasswordChanged) {
        this.lastPasswordChanged = lastPasswordChanged;
    }


    /**
     * toString
     * @return String
     */
     public String toString() {
	  StringBuffer buffer = new StringBuffer();

      buffer.append(getClass().getName()).append("@").append(Integer.toHexString(hashCode())).append(" [");
      buffer.append("username").append("='").append(getUsername()).append("' ");
      buffer.append("passWord").append("='").append(getPassword()).append("' ");
      buffer.append("lastLogin").append("='").append(getLastLogin()).append("' ");
      buffer.append("lastPasswordChanged").append("='").append(getLastPasswordChanged()).append("' ");
      buffer.append("]");

      return buffer.toString();
     }


   public boolean equals(Object other) {
         if ( (this == other ) ) return true;
		 if ( (other == null ) ) return false;
		 if ( !(other instanceof Login) ) return false;
		 Login castOther = ( Login ) other;

		 return ( (this.getId()==castOther.getId()) || ( this.getId()!=null && castOther.getId()!=null && this.getId().equals(castOther.getId()) ) )
 && ( (this.getUsername()==castOther.getUsername()) || ( this.getUsername()!=null && castOther.getUsername()!=null && this.getUsername().equals(castOther.getUsername()) ) )
 && ( (this.getPassword()==castOther.getPassword()) || ( this.getPassword()!=null && castOther.getPassword()!=null && this.getPassword().equals(castOther.getPassword()) ) )
 && ( (this.getLastLogin()==castOther.getLastLogin()) || ( this.getLastLogin()!=null && castOther.getLastLogin()!=null && this.getLastLogin().equals(castOther.getLastLogin()) ) )
 && ( (this.getLastPasswordChanged()==castOther.getLastPasswordChanged()) || ( this.getLastPasswordChanged()!=null && castOther.getLastPasswordChanged()!=null && this.getLastPasswordChanged().equals(castOther.getLastPasswordChanged()) ) );
   }

   public int hashCode() {
         int result = 17;

         result = 37 * result + ( getId() == null ? 0 : this.getId().hashCode() );
         result = 37 * result + ( getUsername() == null ? 0 : this.getUsername().hashCode() );
         result = 37 * result + ( getPassword() == null ? 0 : this.getPassword().hashCode() );
         result = 37 * result + ( getLastLogin() == null ? 0 : this.getLastLogin().hashCode() );
         result = 37 * result + ( getLastPasswordChanged() == null ? 0 : this.getLastPasswordChanged().hashCode() );
         return result;
   }

   /**
    * @hibernate.many-to-one
    * 	name="person"
    * 	column="person_id"
    *   not-null="true"
    */
	public Person getPerson() {
		return person;
	}

	public void setPerson(Person person) {
		this.person = person;
	}

	public GrantedAuthority[] getAuthorities() {
		if ( grantedAuthorities == null ) {
			List<GrantedAuthority> gaList = new ArrayList<GrantedAuthority>();
			for ( AccessGroup ag: getPerson().getAccessGroups() ) {
				gaList.addAll(ag.getAccessPermissions());
			}
			grantedAuthorities = gaList.toArray(new GrantedAuthority[]{});
		}
		return grantedAuthorities;
	}

	public boolean isAccountNonExpired() {
		return true;
	}

	public boolean isAccountNonLocked() {
		return true;
	}

	public boolean isCredentialsNonExpired() {
		return true;
	}

	public boolean isEnabled() {
		return true;
	}

}
